a = {'x': 1, 'z': 3 }
b = {'y': 2, 'z': 4 }

## 合并这两个字典
merged = {}

## 遍历字典 a 和 字典 b 合并他们的内容
for key in set(a) | set(b):
    if key in a and key in b:
        merged[key] = a[key] + b[key]
    elif key in a:
        merged[key] = a[key]
    else:
         merged[key] = b[key]

for k,v in merged.items():
    print(k,v)